<!-- dialogs/torrent2.html -->
<button type="button" class="close" ng-click="close()" class="pull-right">&times;</button>
<h1 translate-value-itemslength="{{items.length || 0}}" translate>TORRENTDIALOG2/hdr</h1>

<div style="float:right; margin-top:-25px;">
  <a ng-click="toggleShowAdvanced()"> <i class="glyphicon glyphicon-cog"></i> <span>{{showAdvanced ? 'TORRENTDIALOG/advanced-hide/btn' : 'TORRENTDIALOG/advanced-show/btn'|translate}}</span></a>
  <a ui-sref="settings.tab({tab: 'torrent-search'})" ng-click="close()"> <i class="glyphicon glyphicon-cog"></i> <span translate-once>COMMON/torrent-search-settings/glyph</span></a>
</div>

<div class="torrentDialog_topNav">
  <div class="input-group torrentDialog_searchBar">
    <input type="text" ng-model="query" ng-model-options="{debounce: 500}" focus-watch='searching' ng-change="search(query)" class="form-control" translate-once-placeholder="COMMON/type-your-search/lbl">
    <span class="input-group-btn">
      <button class="btn btn-default" style="height: 40px" ng-click="search(query)" uib-tooltip="{{'TORRENTDIALOG2/search-now/tooltip'|translate}}" tooltip-append-to-body="true">
        <i class="glyphicon glyphicon-search"></i>
      </button>
    </span>
  </div>

  <div class="torrentBtns torrentDialog_qualityBtns">
    <div class="btn-group">
      <button type="button" class="btn btn-default" ng-class="{active: searchquality == ''}" ng-click="setQuality('');" translate-once>COMMON/all/btn</button>
      <button ng-repeat="quality in getSetting('torrenting.searchqualitylist') " ng-click="setQuality(quality)" type="button" class="btn btn-default" ng-class="{active: searchquality == quality}">{{quality}}</button>
    </div>
  </div>
</div>

<!-- active search engines list -->
<div style="padding-bottom: 3px" uib-collapse="!showAdvanced">
  <div class="torrentBtns btn-group">
    <button ng-disabled="name === defaultProvider" type="button" class="btn btn-default" ng-repeat="name in clients | orderBy: name" ng-click="toggleSE(name)" ng-style="{color: name !== defaultProvider ? 'white' : 'gray'}">
      <i class="tb-activeIcon glyphicon glyphicon-{{activeSE[name] ? 'ok' : 'remove'}}"></i>
      &nbsp;{{::name}}&nbsp;
      <i ng-if="isJackett(name)" class="tb-jackettIcon glyphicon glyphicon-jackett-small" style="float:right"></i>
      <loading-spinner ng-show="searchingSE[name]"></loading-spinner>
    </button>
  </div>
</div>

<!-- Require/Ignore Keywords size min/max and minSeeders check boxes -->
<div style="padding-bottom: 3px" uib-collapse="!showAdvanced">
  <div class="row" style="display: flex">
    <div class="checkbox">
      <input type="checkbox" ng-model="minSeedersEnabled" ng-change="setMinSeedersState()" id="tc_gms">
      <label for="tc_gms"><strong translate-once>COMMON/min-seeders/hdr</strong><br> ({{minSeeders}})</label>
    </div>

    <div class="checkbox" ng-show="requireKeywords.length > 0">
      <input type="checkbox" ng-model="requireKeywordsEnabled" ng-change="setRequireKeywordsState()" id="tc_gie">
      <label for="tc_gie"><strong translate-once>TORRENTDIALOG/search-require-keywords/lbl</strong><br>({{requireKeywords}})</label>
    </div>

    <div class="checkbox" ng-show="ignoreKeywords.length > 0">
      <input type="checkbox" ng-model="ignoreKeywordsEnabled" ng-change="setIgnoreKeywordsState()" id="tc_gee">
      <label for="tc_gee"><strong translate-once>TORRENTDIALOG/search-ignore-keywords/lbl</strong><br>({{ignoreKeywords}})</label>
    </div>

    <div class="checkbox" ng-show="serie.customSearchSizeMin == null && globalSizeMin != null">
      <input type="checkbox" ng-model="globalSizeMinEnabled" ng-change="setGlobalSizeMinState()" id="tc_gsm">
      <label for="tc_gsm"><strong translate-once>TORRENTDIALOG/search-global-size-min/lbl</strong><br>({{globalSizeMin}} MB)</label>
    </div>

    <div class="checkbox" ng-show="serie.customSearchSizeMin != null">
      <input type="checkbox" ng-model="globalSizeMinEnabled" ng-change="setGlobalSizeMinState()" id="tc_gsm2">
      <label for="tc_gsm2"><strong translate-once>TORRENTDIALOG/search-custom-size-min/lbl</strong><br> ({{serie.customSearchSizeMin}}) MB</label>
    </div>

    <div class="checkbox" ng-show="serie.customSearchSizeMax == null && globalSizeMax != null">
      <input type="checkbox" ng-model="globalSizeMaxEnabled" ng-change="setGlobalSizeMaxState()" id="tc_gsme">
      <label for="tc_gsme"><strong translate-once>TORRENTDIALOG/search-global-size-max/lbl</strong><br>({{globalSizeMax}} MB)</label>
    </div>

    <div class="checkbox" ng-show="serie.customSearchSizeMax != null">
      <input type="checkbox" ng-model="globalSizeMaxEnabled" ng-change="setGlobalSizeMaxState()" id="tc_gsme2">
      <label for="tc_gsme2"><strong translate-once>TORRENTDIALOG/search-custom-size-max/lbl</strong><br> ({{serie.customSearchSizeMax}} MB)</label>
    </div>

  </div>
</div>

<!-- search results -->
<div style="max-height: 660px; overflow-x: auto">
  <table class="torrents table table-condensed white" style="max-height: 800px;overflow-x: auto">
    <thead>
      <tr ng-show="searching">
        <td>
          <p style='text-align:center; padding:10px;'><span translate-once>COMMON/searching/lbl</span><span translate-once>COMMON/searching-please-wait/lbl</span>.</p>
        </td>
      </tr>
    </thead>
    <tbody ng-show="!searching && items.length == 0">
      <tr>
        <th>
          <p translate-once>COMMON/no-results/lbl</p>
          "<strong>{{query}} {{searchquality}}</strong>"
        </th>
      </tr>
    </tbody>
    <tbody ng-show="!searching && error == 'null' ">
      <tr>
        <th>
          <h2 style='text-align:center' translate-once>COMMON/type-your-search/lbl</h2>
        </th>
      </tr>
    </tbody>
    <tbody ng-show="!searching && error != false && error != 'null' ">
      <tr style="font-size: 12px;">
        <td style='text-align:center'>:(</td>
        <td style='text-align:left;white-space:pre-wrap;'>{{errorEngine}}</td>
        <td style='text-align:left;white-space:pre-wrap;' colspan="4">{{error}}</td>
      </tr>
    </tbody>
    <tbody ng-show="!searching && items.length > 0">
      <tr>
        <th>&nbsp;</th>
        <th style="cursor: pointer;text-align:left">
          <u uib-tooltip="{{'COMMON/sort-column/tooltip'|translate}}" tooltip-append-to-body="true" ng-click="setSortBy('engine')"><strong translate-once>COMMON/torrent-engine/lbl</strong><span ng-class="{'sortorder reverse': sortByDir['engine'] === '+', 'sortorder': sortByDir['engine'] === '-'}"></span></u>
        </th>
        <th style="cursor: pointer;text-align:left">
          <u uib-tooltip="{{'COMMON/sort-column/tooltip'|translate}}" tooltip-append-to-body="true" ng-click="setSortBy('sortname')"><strong translate-once>COMMON/torrent-name/lbl</strong><span ng-class="{'sortorder reverse': sortByDir['sortname'] === '+', 'sortorder': sortByDir['sortname'] === '-'}"></span></u>
        </th>
        <th style="cursor: pointer;text-align:right">
          <u uib-tooltip="{{'COMMON/sort-column/tooltip'|translate}}" tooltip-append-to-body="true" ng-click="setSortBy('sizeInt')"><strong translate-once>COMMON/torrent-size/lbl</strong><span ng-class="{'sortorder reverse': sortByDir['sizeInt'] === '+', 'sortorder': sortByDir['sizeInt'] === '-'}"></span></u>
        </th>
        <th style="cursor: pointer;text-align:right">
          <u uib-tooltip="{{'COMMON/sort-column/tooltip'|translate}}" tooltip-append-to-body="true" ng-click="setSortBy('seedersInt')"><strong translate-once>COMMON/torrent-seed/lbl</strong><span ng-class="{'sortorder reverse': sortByDir['seedersInt'] === '+', 'sortorder': sortByDir['seedersInt'] === '-'}"></span></u>
        </th>
        <th style="cursor: pointer;text-align:right">
          <u uib-tooltip="{{'COMMON/sort-column/tooltip'|translate}}" tooltip-append-to-body="true" ng-click="setSortBy('leechersInt')"><strong translate-once>COMMON/torrent-leech/lbl</strong><span ng-class="{'sortorder reverse': sortByDir['leechersInt'] === '+', 'sortorder': sortByDir['leechersInt'] === '-'}"></span></u>
        </th>

      </tr>
      <tr ng-repeat="seed in items | orderBy: sortBy" class="no-animate">
        <td style='width:80px; padding:5px; vertical-align: top;'>
          <a ng-if="!seed.noMagnet" ng-click="select(seed)">
            <i class="glyphicon glyphicon-magnet" uib-tooltip="{{'COMMON/download-magnet/tooltip'|translate}}"></i>
          </a>
          <a ng-if="seed.noMagnet">
            <i class="glyphicon glyphicon-magnet" style="color:gray"></i>
          </a>
          <a ng-if="!seed.noTorrent" ng-click="select(seed)">
            <i class="glyphicon glyphicon-download" uib-tooltip="{{'COMMON/download-torrent/tooltip'|translate}}"></i>
          </a>
          <a ng-if="seed.noTorrent">
            <i class="glyphicon glyphicon-download" style="color:gray"></i>
          </a>
          <!-- sneaky: update the $scope.seed with a dangling ref to the magic hash fetched from a promise.
               It's leaking memory until the torrent dialog is closed, won't be much of a problem imo. -->
          <a ng-if="!seed.noMagnet" ng-href="{{seed.magnetUrl}}" ng-click="seed=submitMagnetLink(seed)">
            <i class="glyphicon glyphicon-link" uib-tooltip="{{'COMMON/magnet-link/tooltip'|translate}}"></i>
          </a>
          <a ng-if="seed.noMagnet">
            <i class="glyphicon glyphicon-link" style="color:gray"></i>
          </a>
          <a ng-if="seed.detailUrl" ng-href="{{::seed.detailUrl}}" target='_blank'>
            <i class="glyphicon glyphicon-info-sign" uib-tooltip="{{'COMMON/torrent-details/lbl'|translate}}"></i>
          </a>
          <a ng-if="!seed.detailUrl">
            <i class="glyphicon glyphicon-info-sign" style="color:gray"></i>
          </a>
        </td>
        <td>
          <a ng-bind="::seed.engine"></a>
        </td>
        <td style="word-break:break-word">
          <a ng-bind-html="::seed.releasename | unsafe" ng-click="select(seed)"></a>
        </td>
        <td style="text-align:right">
          <a ng-bind-html="::seed.size" ng-click="select(seed)" style='white-space:nowrap'></a>
        </td>
        <td style='width:50px; text-align:right'>
          <a  ng-bind="::seed.seeders" ng-click="select(seed)"></a>
        </td>
        <td style='width:50px; text-align:right'>
          <a  ng-bind="::seed.leechers" ng-click="select(seed)"></a>
        </td>
      </tr>
    </tbody>
  </table>
</div>
